<?php 
class XuLy_NHANVIEN extends database
{
	function GetNumRows()
	{
		$sql = 'select * from nhanvien' ;
		$this->setQuery($sql);
		$tb = $this->LoadAllRow();
		$num = count($tb);
		return $num;
	}
	function GetNumRows_p($p)
	{
		$sql = 'select * from nhanvien where phong='.$p ;
		$this->setQuery($sql);
		$tb = $this->LoadAllRow();
		$num = count($tb);
		return $num;
	}
	function danhsachtheophong($start,$limit,$phong)
	{
		$this->setQuery('set names utf8');
		$this->Query();
	
		$sql = 'select nv.*,p.tenphong from nhanvien nv,phongban p where p.maphong=nv.phong and nv.phong='.$phong.' limit '.$start.','.$limit ;
		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;
	}	
	function danhsachall($start,$limit)
	{
		$this->setQuery('set names utf8');
		$this->Query();
	
		$sql = 'select nv.*,p.tenphong from nhanvien nv,phongban p where nv.phong=p.maphong limit '.$start.','.$limit ;
		
		
		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;
	}
	function chitiet($ma)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select nv.*,p.tenphong from nhanvien nv,phongban p where nv.phong=p.maphong and manv='.$ma;
		
//		echo $sql;
		
		$this->setQuery($sql);
		$ret = $this->LoadAllRow();
		return $ret;
	}
	function themmoi($hoten,$ngaysinh,$diachi,$phai,$luong,$phong)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'insert into nhanvien(hoten,ngaysinh,diachi,phai,luong,phong) values(\''.$hoten.'\',\''.$ngaysinh.'\',\''.$diachi.'\','.$phai.','.$luong.','.$phong.')';
		
//		echo $sql;
		
		$this->setQuery($sql);
		$kq = $this->Query();
		return $kq;
	}
	function capnhat($ma,$hoten,$ngaysinh,$diachi,$phai,$luong,$phong)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'update nhanvien 
				set hoten=\''.$hoten.'\' , '.
					'ngaysinh=\''.$ngaysinh.'\','.
					'diachi=\''.$diachi.'\' , '.
					'phai='.$phai.','.
					'luong = '.$luong.','.
					'phong = '.$phong.' '.
					'where manv='.$ma;
		
//		echo $sql;
		
		$this->setQuery($sql);
		$kq = $this->Query();
		return $kq;
	}	
	function xoa($ma)
	{
		$sql = 'delete from nhanvien where manv='.$ma;
		
//		echo $sql;
		
		$this->setQuery($sql);
		$rs = $this->Query();
		return $rs;
	}
}
?>